//
//  HYVideoMoreListCell.m
//  XPlayer
//
//  Created by 张水 on 2023/10/12.
//

#import "HYVideoMoreListCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "HYVideoModel.h"

@interface HYVideoMoreListCell()

@property (nonatomic, strong) UIImageView *thumbnailImageView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *sizeLabel;

@end

@implementation HYVideoMoreListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = AppContentBgThemeColor;
        [self configUI];
    }
    return self;
}
- (void)configUI
{
    [self.contentView addSubview:self.thumbnailImageView];
    [self.thumbnailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).offset(12);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.equalTo(@80);
        make.height.equalTo(@45);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thumbnailImageView.mas_top);
        make.leading.equalTo(self.thumbnailImageView.mas_trailing).offset(12);
    }];
    
    [self.thumbnailImageView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.thumbnailImageView.mas_bottom);
        make.centerX.equalTo(self.thumbnailImageView.mas_centerX);
    }];
    
    [self.contentView addSubview:self.sizeLabel];
    [self.sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.titleLabel.mas_leading);
        make.bottom.equalTo(self.thumbnailImageView.mas_bottom);
    }];
}

- (void)bindViewModel:(HYVideoModel *)vm
{
    if (vm.videoImage) {
        self.thumbnailImageView.image = vm.videoImage;
    }
    
    if (vm.videoImagePath.length) {
        [self.thumbnailImageView sd_setImageWithURL:[NSURL URLWithString:vm.videoImagePath] placeholderImage:nil];
    }
    
    self.titleLabel.text = vm.videoTitle;
    self.sizeLabel.text = vm.videoSize;
    self.timeLabel.text = vm.videoDuration;
}

- (UIImageView *)thumbnailImageView
{
    if (!_thumbnailImageView) {
        _thumbnailImageView = [[UIImageView alloc]init];
        _thumbnailImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _thumbnailImageView;
}

- (UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc]init];
    }
    return _iconImageView;
}

- (UILabel *)timeLabel
{
    if(!_timeLabel){
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_SIZE(12);
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.textColor = APPTextThemeColor;
    }
    return _timeLabel;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = FONT_SIZE(12);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = APPTextThemeColor;
    }
    return _titleLabel;
}

- (UILabel *)sizeLabel
{
    if(!_sizeLabel){
        _sizeLabel = [[UILabel alloc]init];
        _sizeLabel.font = FONT_SIZE(12);
        _sizeLabel.textAlignment = NSTextAlignmentCenter;
        _sizeLabel.textColor = APPTextThemeColor;
    }
    return _sizeLabel;
}

@end
